<?php
	
class Table_Photos extends Zend_Db_Table_Abstract
{
    protected $_name    = 'photo';
    protected $_primary = array('PHOTO_NUMERO', 'VIP_NUMERO');
    protected $_sequence = true; //la table a un autoincrément
    
    public function supprimerPhoto($idPhoto, $idVip) {
    	$tablePhoto = new Table_Photos();
		$tableComporte = new Table_Comporte();
		
		$where = 'VIP_NUMERO = '.$idVip.' AND PHOTO_NUMERO = '.$idPhoto;		
		$tableComporte -> delete($where);
		$tablePhoto -> delete($where);
    }
    
    public function setPhotos($numphoto, $numvip, $name,$sujet,$commentaire){
    	
	  	$data=array('PHOTO_NUMERO' => $numphoto,
					'VIP_NUMERO'   => $numvip,
					'PHOTO_SUJET'  => $sujet,
					'PHOTO_COMMENTAIRE' => $commentaire,
					'PHOTO_ADRESSE' => $name);
					
		$this->insert($data);
    }
    
   	public function getPhoto($idPhoto, $idVip)
	{
		return $this -> fetchRow($this
			->select()
			->where('photo_numero = ?', $idPhoto)
			->where('vip_numero = ?', $idVip)
		);
	}

	public function getAdressePhoto($idPhoto, $idVip)
	{
		return $this -> fetchRow($this
			->select()
			->from($this, array('photo_adresse'))
			->where('photo_numero = ?', $idPhoto)
			->where('vip_numero = ?', $idVip)
		);
	}
	
	public function getNbPhotos() {
		return $this -> fetchAll($this
			->select()
			->distinct()
			->from($this, array('*'))
			->order('PHOTO_NUMERO ASC')
		);    
	}

	public function getCommentairePhoto($idPhoto, $idVip)
	{
		return $this -> fetchRow($this
			->select()
			->from($this, array('photo_commentaire'))
			->where('photo_numero = ?', $idPhoto)
			->where('vip_numero = ?', $idVip)
		);
	}
	public function getPhotoPrincipale($idVip)
	{
		return $this->fetchRow($this->select()
                                    ->where('VIP_NUMERO = ?', $idVip)
                                    ->where('PHOTO_NUMERO = ?', 1)
                                );
	}
	
	public function getAllphotos($id)
	{
		return $this->fetchAll($this->select()
									->from($this, array('*'))
                                    ->where('VIP_NUMERO = ?', $id)
                                );
	}
	
}
?>